<?php
/**
 * Created by PhpStorm.
 * User: goouc
 * Date: 2019/10/8
 * Time: 18:10
 */
global $_W,$_GPC;
$sonid = $_GPC['sonid'];
$uid = $_GPC['uid'];
if(empty($uid)){
    return $this->getresult(1,'请先登录',array('code'=>3001,'msg'=>'请先登录'));
}
if(empty($sonid)){
    return $this->getresult(1,'请先选择章节');
}
/***校验token开始***/
if($uid){
    $token = $_GPC['token'];
    if (empty($token)) {
        return $this->getresult(1, '请重新登录', ['code' => 4001, 'msg' => '请重新登录']);
    }
    $token_result = $this->checktoken($uid, $token);
    if ($token_result == 1002) {
        return $this->getresult(1, '请重新登录', ['code' => 4002, 'msg' => '请重新登录']);
    } elseif ($token_result == 1003) {
        return $this->getresult(1, '请重新登录', ['code' => 4003, 'msg' => '请重新登录']);
    }elseif ($token_result == 1001) {
        //  更新token
        pdo_update($this->t_user_token,array('createtime'=>time()),array('uid' => $uid, 'token' => $token, 'weid' => $_W['uniacid']));
    }
}
/***校验token结束***/
$list = pdo_fetchall("select u.nickname,lm.content,lm.createtime,lm.type,lm.name,lm.size from ".tablename($this->t_live_message)." lm JOIN ".tablename($this->t_user)." u ON lm.uid = u.id where lm.weid = :weid and lm.sonid = :sonid order by lm.createtime ASC ",[':weid'=>$_W['uniacid'],':sonid'=>$sonid]);
foreach($list as $k=>$v){
    if($v['type'] == 0){
        $list[$k]['data'] = json_decode($v['content'],true);
    }elseif($v['type'] == 1){
        $list[$k]['img'] = json_decode($v['content'],true);
    }else{
        $list[$k]['file'] = json_decode($v['content'],true);
        $list[$k]['title'] = $v['name'];
    }
}
return $this->getresult(1,'聊天记录',['code'=>200,'list'=>$list]);